package Leetcode.排序;

import java.util.Arrays;

/**
 * @ClassName 俄罗斯套娃信封
 * @since: 2023/9/14 19:30
 * @auth: kirito
 * @description:
 **/
public class 俄罗斯套娃信封 {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     *
     * @param envelopes int整型二维数组
     * @return int整型
     */
    public int maxEnvelopes (int[][] envelopes) {
        int m = envelopes.length;
        int n = envelopes[0].length;
        Arrays.sort(envelopes);

        int[][] res = new int[m+1][n+1];

        return res[m][n];
    }
    public static void sort(int[][] envelopes) {
        for (int j = 0; j < envelopes.length; j++) {
            for (int i = 0; i < j; i++) {
                if(envelopes[i][0]>envelopes[i+1][0]){
                    int[] temp = envelopes[i];
                    envelopes[i] = envelopes[i+1];
                    envelopes[i+1] = temp;
                }else if(envelopes[i][0]==envelopes[i+1][0]){
                    if (envelopes[i][1] > envelopes[i + 1][1]) {
                        int[] temp = envelopes[i];
                        envelopes[i] = envelopes[i+1];
                        envelopes[i+1] = temp;
                    }
                }
            }
        }

    }

    public static void main(String[] args) {
        int[][] arr = {{1,2},
                        {2,1},
                        {1,1},
                        {3,3},
        };
        sort(arr);
        for (int[] a : arr) {
            for (int s : a) {
                System.out.print(s+" ");
            }
            System.out.println();
        }
    }
}
